package com.cos.lession70.util;

import java.io.IOException;
import java.util.Properties;

/**
 * @author: COS
 * @time: 2022/9/26 10:41
 * @description:
 */
public class MyFactory {
    private String path = null;
    private Properties pro = new Properties();

    public MyFactory(String path) {
        try {
            this.path = path;
//        读取并加载配置文件
            pro.load(MyFactory.class.getResourceAsStream(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Object getBean(String beanName) {
        try {
            //反射
            Class<?> aClass = Class.forName(pro.getProperty(beanName));
            return aClass.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

}
